import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
* @author :${author}
* @description: ${desc} controller
* @create date: ${createDate}
*/


@RestController
@RequestMapping(value = "${entityNameLower}")
@Api(value="${entityName}controller",tags={"${desc} 信息接口"})
public class ${entityName}Controller {

    @Autowired
    ${entityName}Service ${entityNameLower}Service;

    @ApiOperation(value = "添加${desc}信息")
    @PostMapping(value = "add")
    public ${returnCls}<Integer> add(@RequestBody @Validated(${entityName}Dto.Add.class) ${entityName}Dto ${entityNameLower}Dto ){
        return ${entityNameLower}Service.add(${beanUtils}.copyTo(${entityNameLower}Dto, ${entityName}.class)) > 0?
        ${returnSuccess}():${returnFail}();
    }

    @ApiOperation(value = "修改${desc}信息")
    @PostMapping(value = "update")
    public ${returnCls}<Integer> update(@RequestBody @Validated(${entityName}Dto.Update.class) ${entityName}Dto ${entityNameLower}Dto){
        return ${entityNameLower}Service.update(${beanUtils}.copyTo(${entityNameLower}Dto, ${entityName}.class)) > 0?
                ${returnSuccess}():${returnFail}();
     }

    @ApiOperation(value = "删除${desc}信息")
    @PostMapping(value = "del")
    public ${returnCls} <Integer> del(@RequestBody @Validated(${entityName}Dto.Delete.class) ${entityName}Dto ${entityNameLower}Dto ){
        return ${entityNameLower}Service.delete(${beanUtils}.copyTo(${entityNameLower}Dto, ${entityName}.class))> 0?
                        ${returnSuccess}():${returnFail}();
    }

    @ApiOperation(value = "查询${desc}信息详情")
    @PostMapping(value = "detail")
    public ${returnCls}<${entityName}Vo> detail(@RequestBody ${entityName}Dto ${entityNameLower}Dto ){
        return ${returnSuccess}(${entityNameLower}Service.detail(${beanUtils}.copyTo(${entityNameLower}Dto, ${entityName}.class)));
    }

    @ApiOperation(value = "查询${desc}信息列表")
    @PostMapping(value = "list")
    public ${returnCls}<List<${entityName}Vo>> findList(@RequestBody ${entityName}Dto ${entityNameLower}Dto ){
        return ${returnSuccess}(${entityNameLower}Service.findList(${beanUtils}.copyTo(${entityNameLower}Dto, ${entityName}.class)));
    }

    @ApiOperation(value = "查询${desc}分页列表信息")
    @PostMapping(value = "pagelist")
    public ${returnCls} findPageList(@RequestBody ${entityName}PageDto ${entityNameLower}PageDto ){
        Integer pageNum = ${entityNameLower}PageDto.getPageNum();
        Integer pageSize = ${entityNameLower}PageDto.getPageSize();
        ${entityNameLower}PageDto.setPageNum(pageNum==null?1:pageNum);
        ${entityNameLower}PageDto.setPageSize(pageSize==null?10:pageSize);
        return ${returnSuccess}( ${entityNameLower}Service.findPageList(${entityNameLower}PageDto));
    }
}